import {
  getRoleList,
  getViewRoleList
  // editVideoList
} from '@/api/system'

const state = {
  roleData: [],
  roleDataCount: 0
}

const mutations = {
  GET_ROLE_DATA: (state, data) => {
    state.roleData = data
  },
  GET_ROLE_DATA_COUNT: (state, data) => {
    state.roleDataCount = data
  }
}

const actions = {
  async getRoleData({ commit }, playload) {
    let data = {}
    let newData = []
    if (Object.keys(playload).length > 0) {
      data = playload
    }
    const resp = await getRoleList(data)
    resp.data.data.map((item) => {
      newData = [...newData, {
        role: item.role,
        gname: item.gname,
        ctime: item.ctime,
        mtime: item.mtime
      }]
    })
    // for (let i = 0; i < 5; i++) {
    //   newData = [...newData, {
    //     id: i + 1,
    //     name: '超级管理员',
    //     state: '启动',
    //     ctime: '2019-04-24 14:58:00',
    //     updatetime: '2019-04-24 14:58:00'
    //   }]
    // }
    commit('GET_ROLE_DATA', newData)
    // commit('GET_ROLE_DATA_COUNT', newData.length)
    return resp
  },
  // async editRoleData({ commit }, playload) {
  //   const resp = await editVideoList(playload)
  //   return resp
  // }
  async getViewRoleData({ commit }, playload) {
    let data = {}
    const newData = []
    if (Object.keys(playload).length > 0) {
      data = playload
    }
    const resp = await getViewRoleList(data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
